package com.aca.action;

import com.aca.entity.Scene;
import com.aca.service.RoleService;
import com.aca.service.SceneService;
import com.aca.tool.Pager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import java.util.Map;

public class SceneAction extends ActionSupport {
    private Scene scene;
    private RoleService roleService;
    private SceneService sceneService;
    private int pageCur = 1;
    private int pageSize = 2;// 通常设为10

    public Scene getScene() {
        return scene;
    }

    public void setScene(Scene scene) {
        this.scene = scene;
    }

    public RoleService getRoleService() {
        return roleService;
    }

    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    public SceneService getSceneService() {
        return sceneService;
    }

    public void setSceneService(SceneService sceneService) {
        this.sceneService = sceneService;
    }

    public int getPageCur() {
        return pageCur;
    }

    public void setPageCur(int pageCur) {
        this.pageCur = pageCur;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }

    public String sceneList() throws Exception{
        List list = sceneService.pageScene(pageCur, pageSize, scene);
        Pager page = new Pager(pageCur,pageSize,sceneService.getSceneTol());
        Map request=(Map) ActionContext.getContext().get("request");
        request.put("list",list);
        request.put("page",page);
        return SUCCESS;
    }
    public String sceneAddView() throws Exception{
        return SUCCESS;
    }
    public String sceneAdd() throws Exception{
        if(scene.getSname().length()!=0 && sceneService.findScene(scene.getSname())==null){
            sceneService.addScene(scene);
            return SUCCESS;
        }else{
            return ERROR;
        }
    }
    public String sceneDelete()throws Exception{
        sceneService.delScene(scene.getSname());
        return SUCCESS;
    }
    public String sceneUpdateView() throws Exception{
        List list=sceneService.findSceneBySno(scene.getSno());
        return SUCCESS;
    }
    public String sceneUpdate()throws Exception{
        sceneService.updateScene(scene);
        return SUCCESS;
    }
}
